
import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../Vuex';
import routes from './rotuer'

Vue.use(VueRouter)


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});
router.beforeEach((to,from,next)=>{
    if(to.path =='/detalist'){
       if(to.fullPath == '/detalist'){
            next(-1);
       }
      store.commit("setDetalist",true);
    }else{
      store.commit("setDetalist",false);
    }
    store.commit("setToPath",to.name);
    if(to.meta.auth){//路由守卫，看是否需要
      if(!$Cookies.get("userId")){
         store.commit("setLogin",false);
         store.commit("setLoginGui",true);
      }else{
        next();
      }
    }else{
      next();
    }
    
})
export default router
